package com.itheima.demo;

import com.itheima.domain.Orders;
import com.itheima.domain.User;
import com.itheima.mapper.OrdersMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.util.List;

public class Demo {
    public static void main(String[] args) throws Exception {
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("sql.xml"));
        SqlSession session = factory.openSession();
        OrdersMapper mapper = session.getMapper(OrdersMapper.class);
        List<Orders> all = mapper.findAll();
        for (Orders orders : all) {
            System.out.println("订单编号:"+orders.getNumber());
            System.out.println("用户名称:"+orders.getUser().getUsername());
        }
        session.close();
    }
}
